import type { Meta, StoryObj } from "@storybook/react";
import "../../styles/index.scss";
import VirtualScrollList from "./VirtualScrollList";
import { Random } from "mockjs";
import Item, { ItemProps } from "./Item";
import { fn } from "@storybook/test";
const meta = {
  title: "components/VirtualScrollList",
  component: VirtualScrollList,
  parameters: {
    // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/configure/story-layout
    layout: "centered",
  },
  // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/writing-docs/autodocs
  tags: ["autodocs"],
  // More on argTypes: https://storybook.js.org/docs/api/argtypes
  argTypes: {},
  // Use `fn` to spy on the onClick arg, which will appear in the actions panel once invoked: https://storybook.js.org/docs/essentials/actions#action-args
  args: {},
} satisfies Meta<typeof VirtualScrollList>;

export default meta;
type Story = StoryObj<typeof meta>;

export const DefaultVirtualScrollList: Story = {
  args: {
    size: 30,
    dataSources: [],
    dataKey: "",
    estimateSize: 100,
    DataComponent: Item,
  },
  render: () => {
    const totalCount = 10000;
    interface DataType {
      id: number;
      name: string;
      desc: string;
      index: number;
    }
    const data: DataType[] = [];
    let index = 0;
    while (index++ !== totalCount) {
      data.push({
        id: index,
        name: Random.cname(),
        desc: Random.csentence(20, 120),
        index: index,
      });
    }

    return (
      <div style={{ width: "500px" }}>
        <VirtualScrollList
          dataSources={data}
          size={30}
          dataKey="id"
          estimateSize={100}
          DataComponent={Item}
        ></VirtualScrollList>
      </div>
    );
  },
};
